package com.example.liuliang.beepproject;


        import android.os.Bundle;
        import android.support.v7.app.AppCompatActivity;
        import android.view.View;
        import android.widget.Button;
        import android.widget.Toast;

        import com.cbtService.AndroidSDK.BeepService;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button bt1,bt2,bt3,bt4;
    int a=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BeepService beepService=new BeepService();
        beepService._init();
        init();
    }

    private void init() {
        bt1=(Button)findViewById(R.id.button1);
        bt2=(Button)findViewById(R.id.button2);
        bt3=(Button)findViewById(R.id.button3);
        bt4=(Button)findViewById(R.id.button4);
        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        bt3.setOnClickListener(this);
        bt4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.button1:
                BeepService.PWMPlay(0);
                break;
            case R.id.button2:
                BeepService.PWMStop();
                break;
            case R.id.button3:
                if(a<=20){
                    for(int i=0;i<=20;i++){
                        BeepService.PWMPlay(i);
                        a++;
                    }
                }else{
                    Toast.makeText(this, "已经到最大值", Toast.LENGTH_SHORT).show();
                    a=20;
                }
                break;

            case R.id.button4:
                if(a>=0){
                    for(int i=20;i>=0;i--){
                        BeepService.PWMPlay(i);
                        a--;
                    }
                }else{
                    Toast.makeText(this, "已经到最小值", Toast.LENGTH_SHORT).show();
                    a=0;
                }
                break;
        }
    }
}
